import {mapGetters} from 'vuex';
import {Balance, Withdraw} from '../../Common/';
import {cbs} from '../../../config/settings.js';

module.exports = {
	name: 'homePage',
	data() {
		return{
			balanceMenu: [{
				text: '提现',
				command: 'withdraw'
			}],
			size: 5,
			page: 1,
			withdrawVisible: false,
			tipsVisible: false,
			isClose: false
		}
	},
	components: {
		Balance,
		Withdraw
	},
	methods: {
		/**
         * 获取空桶订单数
         */
		getOrderHint() {
			let data = this.$$formData({
				size: this.size,
				page: this.page
			})

			this.$$api_order_emptyBarrelTotal(data, res => {
		        if(res.event === 0) {
	   	            this.$store.dispatch('update_empty_barrel_orders', res.obj);cbs
		        }else {
		            cbs.submitError.call(this, `获取信息失败，${res.msg}`);
	            }
	        })
		},
		/**
         * 获取账户余额
         */
		getBalance() {
	        this.$refs.balance.getBalance();
	    },
	    /**
         * 获取新订单
         */
	   //  getNewOrder() {
	   //  	let data = this.$$formData({
				// size: this.size,
				// pageNum: this.page
	   //  	})

	   //  	this.$$api_order_newList(data, res => {
	   //  		if(res.event === 0) {
	   //  			this.$store.dispatch('update_new_list', res.obj)
	   //  			this.$store.dispatch('update_new_orders', res.maxCount)
	   //  		}else {
	   //  			cbs.submitError.call(this, `获取新订单信息失败，${res.msg}`);
	   //  		}
	   //  	})
	   //  },
	    /**
         * 查看更多新订单
         */
	    // onMore() {
	    // 	this.$router.push('/order/new-list');
	    // },
		/**
         * 提取
         */
		onWithdraw() {
			this.hasPayPwd ? this.withdrawVisible = true : this.tipsVisible = true;
		},
		/**
         * 接收新订单
         */
		// onReceiveOrder(id) {
		// 	let data = this.$$formData({
		// 		orderWaterStoreId: id
		// 	})
		// 	this.$$api_order_receiveOrder(data, res => {
		// 		if(res.event === 0) {
		// 			this.getOrderHint();
		// 			this.getNewOrder();
		// 		}else {
		// 			cbs.submitError.call(this, `接收订单失败，${res.msg}，请重新接收`);
		// 		}
		// 	})
		// },
		/**
         * 拒绝新订单
         */
		// onRejectOrder(id) {
		// 	let data = this.$$formData({
		// 		orderWaterStoreId: id
		// 	})
		// 	this.$$api_order_rejectOrder(data, res => {
		// 		if(res.event === 0) {
		// 			this.getOrderHint();
		// 			this.getNewOrder();
		// 		}else {
		// 			cbs.submitError.call(this, `拒绝订单失败，${res.msg}，请重新提交`);
		// 		}
		// 	})
		// },
		/**
         * 关闭提现窗口前
         */
		closeWithdraw() {
			this.withdrawVisible = false;
			this.$refs.withdraw.onClose()
		}
	},
	mounted() {
		this.getBalance();
		this.getOrderHint();
		// this.getNewOrder();
		$('.dialog-withdraw .el-dialog').css('width', '340px');
	},
	computed:{
		...mapGetters({
	        newList: 'getNewList',
	        newOrders: 'getNewOrders',
            emptyBarrel: 'getEmptyBarrelOrders',
            depositeOrders: 'getDepositeOrders'
	    }),
	    hasPayPwd() {
	    	return this.$store.state.user.userinfo.hasPay;
	    }
	}
	
}